package com.mysoft.gfyx.marketdevelop.controller;

import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.marketdevelop.controller.dto.GetProcurementRequirementMobileRequestDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.GetPurchaseContactsRequestDto;
import com.mysoft.gfyx.marketdevelop.service.DeveloperContactService;
import com.mysoft.gfyx.marketdevelop.service.ProcurementRequirementService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

@PubService(value = "/procurementRequirementDataApi", prefix = RequestPrefix.API)
public class ProcurementRequirementDataApiController {

    @Resource
    private ProcurementRequirementService procurementRequirementService;

    @Resource
    private DeveloperContactService developerContactService;

    @PubAction(value = "/getProcurementRequirementMobile", method = RequestMethod.POST)
    public GetProcurementRequirementMobileRequestDto getProcurementRequirementMobile(@RequestBody GetPurchaseContactsRequestDto dto) {
        if (dto.getScene().equals("developer-contact")) {//开发商联系人手机号
            Map<String, Object> developerContact = developerContactService.getContactInfo(dto.getId());
            GetProcurementRequirementMobileRequestDto developerContactDto = new GetProcurementRequirementMobileRequestDto();
            if (!developerContact.isEmpty()) {
                developerContactDto.setTel(developerContact.get("ower_mobile").toString());
                developerContactDto.setName(developerContact.get("ower").toString());
            }
            return developerContactDto;
        } else {//商机联系人手机号
            if (Objects.equals(dto.getType(), "agent")) {
                return procurementRequirementService.getProcurementRequirementAgentMobile(dto.getId());
            } else {
                return procurementRequirementService.getProcurementRequirementMobile(dto.getId());
            }
        }

    }
}
